package com;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.swing.JProgressBar;

public class PbThread implements Runnable{
	private JProgressBar jpb;
	private File srcFile,desFile;
	

	public PbThread(JProgressBar jpb, File srcFile, File desFile) {
		super();
		this.jpb = jpb;
		this.srcFile = srcFile;
		this.desFile = desFile;
	}


	@Override
	public void run() {
		try {
			BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));
			BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(desFile));
			int a = bis.read();
			int c = 0;
			long len = srcFile.length();
			int percent;
			while (a != -1) {
				bos.write(a);
				c++;
				percent = (int) (1.0 * c / len * 100);
				jpb.setValue(percent);
				a = bis.read();
			}
			bis.close();
			bos.flush();
			bos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
